import poplib,string,email
from email.Header import Header

def pop3conn(host,account,password):
        mailInBox=poplib.POP3(host)
        mailInBox.user(account)
        mailInBox.pass_(password)

        addressList=[]
        mailnum,mailsize=mailInBox.stat()
        for selected in range(0,mailnum):
                response,message,content=mailInBox.retr(selected+1)
                messageString=email.message_from_string(string.join(message,'\n'))
                type=messageString.get_content_charset()
                if type=='gb2312':
                        unicode(messageString.get_payload(),'gb2312')
                if type=='shift_jis':
                        unicode(messageString.get_payload(),'shift_jis')
                if type=='None':
                        unicode(messageString.get_payload(),'utf-8')
                messageFrom=email.Header.decode_header(messageString['from'])[0][0]
                addressList.append(messageFrom)
        return addressList
